export function on (el, type, fn) {
  el.addEventListener(type, fn, false)
}

export function off (el, type, fn) {
  el.removeEventListener(type, fn, false)
}

export const sleep = t => new Promise(r => setTimeout(r, t))

// 进入全屏
export function requestFullScreen () {
  let elem = document.documentElement
  if (elem.requestFullscreen) {
    elem.requestFullscreen()
  } else if (elem.mozRequestFullScreen) {
    elem.mozRequestFullScreen()
  } else if (elem.webkitRequestFullScreen) {
    elem.webkitRequestFullScreen()
  } else if (elem.msRequestFullscreen) {
    document.body.msRequestFullscreen()
  }
}

// 退出全屏
export function exitFullscreen () {
  let doc = document
  if (doc.exitFullscreen) {
    doc.exitFullscreen()
  } else if (doc.mozCancelFullScreen) {
    doc.mozCancelFullScreen()
  } else if (doc.webkitCancelFullScreen) {
    doc.webkitCancelFullScreen()
  } else if (doc.msExitFullscreen) {
    document.msExitFullscreen()
  }
}
 
export const deepClone = v => JSON.parse(JSON.stringify(v))

export function pathJoin (...args) {
  return args.map((e, index) => {
    if (index === 0) {
      if (/^\/+$/.test(e)) return '/'
      return e.replace(/\/+$/g, '')
    }
    return e.replace(/^\/+|\/+$/g, '')
  }).filter(e => !!e).join('/').replace(/^\/+/g, '/')
}

/**
 * 类型判断
 * @param {any} v
 * @param {'String'|'Number'|'Object'|'Array'|'Boolean'|'Null'|'Undefined'|'Symbol'|'Function'|'AsyncFunction'} type
 * @returns {Boolean}
 * **/
export function is (v, type) {
  return Object.prototype.toString.call(v) === `[object ${type}]`
}
